package com._520it.crm.web.controller;


import com._520it.crm.domain.AuditInfo;
import com._520it.crm.domain.AuditInsurance;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.AuditInsuranceQueryObject;
import com._520it.crm.service.IAuditInsuranceService;
import com._520it.crm.util.AjaxResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;

@Controller
@RequestMapping("/auditInsurance")
public class AuditInsuranceController {

    @Autowired
    private IAuditInsuranceService auditInsuranceService;


    @RequestMapping("")
    public String index(){
        return "auditInsurance";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(AuditInsuranceQueryObject qo){
        PageResult result = null;
        result = auditInsuranceService.query(qo);
        return result;
    }


    //提交到审核表

    @RequestMapping("submit")
    @ResponseBody
    public AjaxResult submit(Long id){
        AjaxResult result = null;
        try {
            auditInsuranceService.updateAuditTime(id);
            result = new AjaxResult("提交成功");
        }catch (Exception e){
            e.printStackTrace();
            result = new AjaxResult(false,"提交失败");
        }
        return result;
    }


    //暂存
    @RequestMapping("/temporary")
    public String temporary(){
        return "auditInsuranceTemporary";
    }
    //暂存数据
    @RequestMapping("/temporaryData")
    @ResponseBody
    public PageResult temporaryData(AuditInsuranceQueryObject qo){
        PageResult result = null;
        qo.setA(1);
        result = auditInsuranceService.query(qo);
        return result;
    }




    @RequestMapping("/auditInsurancePass")
    public String auditInsurancePass() {
        return "auditInsurancePass";
    }

    @RequestMapping("/auditInsurancePassDate")
    @ResponseBody
    public PageResult auditInsurancePassDate(AuditInsuranceQueryObject qo){
        PageResult result = null;
        qo.setA(2);
        result = auditInsuranceService.query(qo);
        return result;
    }





    @RequestMapping("/auditHistoryData")
    @ResponseBody
    public PageResult auditHistoryData(Long id){
        PageResult pr = new PageResult();
        AuditInsurance ai = auditInsuranceService.auditHistoryData(id);
        pr.setTotal(1);
        pr.setRows(Arrays.asList(ai));
        return pr;
    }









}
